package com.controller;

import com.dto.excution.ListExcution;
import com.entity.RewardInfo;
import com.enums.ListEnum;
import com.service.RewardService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by Administrator on 2019/1/10 0010.
 */
@RequestMapping("reward")
@RestController
public class RewardController {
    @Autowired
    private RewardService service;

    @ApiOperation(value = "查询赞赏记录")
    @PostMapping(value = "/findRewardList")
    @ResponseBody
    public ListExcution<List<RewardInfo>> findRewardList(Integer limit){
        List<RewardInfo> list = service.findRewardList(limit);
        return new ListExcution<List<RewardInfo>>(list, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "修改课时价格")
    @PostMapping(value = "/updatePrice")
    @ResponseBody
    public ListExcution<Void> updatePrice(Integer userId,String hourPrice){
        int price = service.updatePrice(userId,hourPrice);
        if(price > 0){
            return new ListExcution<Void>(null, ListEnum.SUCCESS);
        }else{
            return new ListExcution<Void>(null, ListEnum.FAIL);
        }
    }

    @ApiOperation(value = "新增充值表和流水")
    @PostMapping(value = "/addMoney")
    @ResponseBody
    public ListExcution<Void> addMoney(Integer userId, BigDecimal money,String nonceStr,BigDecimal discount){
        int price = service.addMoney(userId,money,nonceStr,discount);
        if(price > 0){
            return new ListExcution<Void>(null, ListEnum.SUCCESS);
        }else{
            return new ListExcution<Void>(null, ListEnum.FAIL);
        }
    }

}
